package net.hn.hnms.biz.plan.group.controller;

import io.swagger.annotations.*;
import net.hn.hnms.biz.plan.company.service.CompanyStatisticService;
import net.hn.hnms.biz.plan.domain.TreeStringEntity;
import net.hn.hnms.biz.plan.group.service.GroupStatisticService;
import net.hn.hnms.biz.plan.request.SaleAnalyseReq;
import net.hn.hnms.biz.plan.vo.*;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Api(value = "计划集团统计相关", tags = {"计划集团统计相关"})
@RestController
@RequestMapping("/groupStatistic")
@EnableScheduling
public class GroupStatisticController {


    @Autowired
    private GroupStatisticService groupStatisticService;

    @Autowired
    private CompanyStatisticService companyStatisticService;

    @ApiOperation("集团端-月产统计")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/plan/outputCount")
    @AutoSetMineCode
    public R<List<PlanStatisticVO>> outputCount(Integer month, String companyCode) {
        return R.ok(groupStatisticService.outputCountmonthAndYear(month, companyCode));
    }

    @ApiOperation("集团端-月产统计月产量点击")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/plan/monthoutput")
    @AutoSetMineCode
    public R<List<PlanStatisticVO>> monthoutput(Integer month) {
        return R.ok(groupStatisticService.monthoutput(month));
    }





    @ApiOperation("集团端-年产统计量点击")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/plan/yearoutput")
    @AutoSetMineCode
    public R<List<PlanStatisticVO>> yearoutput( ) {
        return R.ok(groupStatisticService.yearoutput());
    }





    @ApiOperation("集团端-经营综合概览-产量")
    @GetMapping("/outputStatistic")
//    @AutoSetMineCode
    public R<MonthYieldVo> outputStatistic(Integer month, String companyCode) {
        return R.ok(groupStatisticService.outputStatistic(month, companyCode));
    }
    @ApiOperation("集团端-经营综合概览-产量弹框")
    @GetMapping("/outputStatisticDetail")
//    @AutoSetMineCode
    public R<List<MonthYieldVo>> outputStatisticDetail(Integer month, String companyCode) {
        return R.ok(groupStatisticService.outputStatisticDetail(month, companyCode));
    }
    @ApiOperation("集团端-经营综合概览-产量汇聚")
    @GetMapping("/outputStatisticConverge")
//    @AutoSetMineCode
    public R< List<TreeStringEntity<MonthYieldVo>>> outputStatisticConverge(Integer month, String companyCode) {
        return R.ok(groupStatisticService.outputStatisticConverge(month, companyCode));
    }


    @ApiOperation("集团端-经营综合概览-产量详情(type=1为月，2为年)")
    @GetMapping("/outputStatisticDetailed")
//    @AutoSetMineCode
    public R<List<PlanStatisticVO>> outputStatisticDetailed(Integer month,Integer type, String companyCode) {
        return R.ok(groupStatisticService.outputStatisticDetailed(month,type,companyCode));
    }


    @ApiOperation("集团端-产量计划与实际对比(结果[0]是实际[1]是计划)")
    @GetMapping("/getProduction")
    public R<Map<String, BigDecimal[]>> getProduction(@ApiParam("(type 1煤业，2公司，3矿)") Integer type, @ApiParam("(level 1年，2月，3日)") Integer level,String companyCode) {
        return R.ok(groupStatisticService.getProduction(type,level,companyCode));
    }

    @ApiOperation("集团端-月掘进变化趋势")
    @GetMapping("/getMonthlyTrendOfExcavation")
    public R<List<MonthOuputVO>> getMonthlyTrendOfExcavation(@ApiParam("煤矿编码")String mineCode, @ApiParam("2掘进/1剥离")String type) {
        return R.ok(groupStatisticService.getMonthlyTrendOfExcavation(mineCode,type));
    }
    @ApiOperation("集团端-月掘下拉框")
    @GetMapping("/getMonthlySelect")
    public R< List<Map<String, String>>> getMonthlySelect(@ApiParam("1掘进/0剥离")String type) {
        return R.ok(groupStatisticService.getMonthlySelect(type));
    }
    @ApiOperation("获取所有煤矿编码")
    @GetMapping("/getMineCode")
    public R< Map<String, String>> getMineCode(String companyCode) {
        return R.ok(groupStatisticService.getMineCode(companyCode));
    }

    @ApiOperation("集团端-掘进年/月计划与实际对比")
    @GetMapping("/compareYearMonthPlanActual")
    public R<List<SaleAnalyseVo>> compareYearMonthPlanActual(@ApiParam("2掘进/1剥离")String type) {
        return R.ok(groupStatisticService.compareYearMonthPlanActual(type));
    }

    @ApiOperation("集团端-掘进/剥离情况")
    @GetMapping("/getDrivingStrippingStatus")
    public R<List<MonthYieldVo>> getDrivingStrippingStatus(@ApiParam("2掘进/1剥离")String type) {
        return R.ok(groupStatisticService.getDrivingStrippingStatus( type));
    }

    @ApiOperation("集团端-产量日情况")
    @GetMapping("/getOutputStatus")
    public R<List<MonthYieldVo>> getOutputStatus() {
        return R.ok(groupStatisticService.getOutputStatus());
    }


    @ApiOperation("集团端-产量变化趋势(type1年，2月，3日)(level 1煤业，2公司)")
    @GetMapping("/getTrendProduction")
    public R<List<MonthOuputVO>> getTrendProduction(Integer type, Integer level,String companyCode) {
        return R.ok(groupStatisticService.getTrendProduction(type,level,companyCode));
    }

    @ApiOperation("集团端-产量变化同比(type1年，2月)矿级")
    @GetMapping("/getOutputYoyandQoq")
    public R<List<MonthOuputVO>> getOutputYoy(Integer type, String mineCode) {
        return R.ok(groupStatisticService.getOutputYoy(type,mineCode));
    }
    @ApiOperation("集团端-销量变化同比环比(type1年，2月)矿级")
    @GetMapping("/getSaleYoyandQoq")
    public R<List<MonthOuputVO>> getSaleYoyandQoq(Integer type, String mineCode) {
        return R.ok(groupStatisticService.getSaleYoyandQoq(type,mineCode));
    }
    @ApiOperation("集团端-产量销量变化同比环比(type1年，2月)矿级")
    @GetMapping("/getOutputSaleYoyandQoq")
    public R<List<CoalMiningTotalVo>> getOutputSaleYoyandQoq(@ApiParam("(type 1年，2月)")Integer type, String mineCode) {
        return R.ok(groupStatisticService.getOutputSaleYoyandQoq(type,mineCode));
    }

    /**
     * 公司、集团、煤矿，的去年产量，去年计划，今年计划、
     * @param type 1公司 2煤矿
     * @param code 公司编码  煤矿编码
     * @return
     */
    @ApiOperation("集团端-生产综合概览-产量情况")
    @GetMapping("/outputStatisticSituation")
//    @AutoSetMineCode
    public R<List<PlanStatisticVO>> outputStatisticSituation(Integer type, String code) {
        return R.ok(groupStatisticService.outputStatisticSituation(type,code));
    }

    @ApiOperation("集团端-生产综合概览-昨日产量昨日计划情况")
    @GetMapping("/laseDayoutputStatisticSituation")
//    @AutoSetMineCode
    public R<List<PlanStatisticVO>> laseDayOutputAndPlanStatisticSituation(Integer type, String code) {
        return R.ok(groupStatisticService.laseDayOutputAndPlanStatisticSituation(type,code));
    }




    @ApiOperation("集团端-生产计划统计")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/plan/complete")
//    @AutoSetMineCode
    public R<Map<String, PlanStatisticVO>> planComplete(Integer month, String companyCode) {
        return R.ok(groupStatisticService.planComplete(month, companyCode));
    }


    @ApiOperation("集团端-剥离进度")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/plan/peel")
    @AutoSetMineCode
    public R<FootAgeVo> peelCount(Integer month, String companyCode) {
        return R.ok(groupStatisticService.peelCount(month, companyCode));
    }

    @ApiOperation("集团端-综合概览年度情况")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/annualSituation")
    @AutoSetMineCode
    public R<MonthValue> annualSituation(String companyCode) {
        return R.ok(groupStatisticService.annualSituation(companyCode));
    }

    @ApiOperation("集团端-工作面情况")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/faceCondition")
//    @AutoSetMineCode
    public R<List<MiningContinuationVo>> faceCondition(String companyCode,String mineCode,Integer type) {
        return R.ok(groupStatisticService.faceCondition(companyCode,mineCode,type));
    }
    @ApiOperation("集团端-工作面采掘接续")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/faceContinuation")
//    @AutoSetMineCode
    public R<List<DimMiningFaceVO>> faceConditionContinuation(String companyCode,String mineCode,Integer type) {
        return R.ok(groupStatisticService.faceConditionContinuation(companyCode,mineCode,type));
    }


    @ApiOperation("集团端-综合概览销售分析")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/saleAnalyse")
//    @AutoSetMineCode
    public R<SaleAnalyseVo> saleAnalyse(SaleAnalyseReq req) {
        return R.ok(groupStatisticService.saleAnalyse(req));
    }

    @ApiOperation("集团端-综合概览销售分析-子菜单")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/saleAnalyseSubmenu")
//    @AutoSetMineCode
    public R<List<SaleAnalyseVo>> saleAnalyseSubmenu(SaleAnalyseReq req) {
        return R.ok(groupStatisticService.saleAnalyseSubmenu(req));
    }


    @ApiOperation("集团端-综合概览产销统计子菜单")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/productionAndMarketingCountSubmenu")
//    @AutoSetMineCode
    public R<List<ProductionAndMarketingVo>> productionAndMarketingCountSubmenu(SaleAnalyseReq req) {
        return R.ok(groupStatisticService.productionAndMarketingCountSubmenu(req));
    }


    @ApiOperation("集团端-综合概览产销统计")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/productionAndMarketingCount")
//    @AutoSetMineCode
    public R<Map<String, String[]>> productionAndMarketingCount(SaleAnalyseReq req) {
        return R.ok(groupStatisticService.productionAndMarketingCount(req.getCompanyCode()));
    }


    @ApiOperation("集团端-生产综合概览露天矿和井工矿")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/OpencastAndUndergroundMiningCount")
//    @AutoSetMineCode
    public R<OpencastAndUndergroundMiningVo> OpencastAndUndergroundMiningCount(@ApiParam("公司编码")String companyCode,@ApiParam("矿类型：1露天矿，2井工矿") String type) {
        return R.ok(groupStatisticService.opencastAndUndergroundMiningCount(companyCode,type));
    }

    @ApiOperation("集团端-生产综合概览露天矿和井工矿子菜单")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/opencastAndUndergroundMiningCountSubmenu")
//    @AutoSetMineCode
    public R<List<OpencastAndUndergroundMiningVo>> opencastAndUndergroundMiningCountSubmenu(@ApiParam("公司编码")String companyCode,@ApiParam("矿类型：1露天矿，2井工矿") String type) {
        return R.ok(groupStatisticService.opencastAndUndergroundMiningCountSubmenu(companyCode,type));
    }


    @ApiOperation("集团端-各公司年累计产量")
    @GetMapping("/companyYearTotalYield")
    public R<List<CompanyYearTotalYieldVo>> companyYearTotalYield() {
        return R.ok(groupStatisticService.companyYearTotalYield());
    }

    @ApiOperation("集团端-回采进度统计")
    @GetMapping("/plan/mining")
    public R<FootAgeVo> miningCount(Integer month, String companyCode) {
        return R.ok(companyStatisticService.miningCount(month, companyCode));
    }

    @ApiOperation("集团端-掘进进度统计")
    @GetMapping("/plan/drivage")
    public R<FootAgeVo> drivageCount(Integer month, String companyCode) {
        return R.ok(companyStatisticService.drivageCount(month, companyCode));
    }

    @ApiOperation("集团端-填报分析")
    @GetMapping("/fillingAnalysis")
    public R<Map<String,Object>> getFillingAnalysis(@ApiParam("时间，格式为yyyy-mm")String dateStr,@ApiParam("公司0，报表1，不传默认公司") String type,int pageNum,int pageSize,String companyCode) {
        return R.ok(groupStatisticService.getFillingAnalysis(dateStr,type,pageNum,pageSize,companyCode));
    }

    @ApiOperation("集团端-各类矿井状态")
    @GetMapping("/getMineNumberStatus")
    public R<List<MineNumberVo>> getMineNumberStatus(String companyCode) {
        return R.ok(groupStatisticService.getMineNumberStatus(companyCode));
    }

    @ApiOperation("集团端-各类矿井数")
    @GetMapping("/getMineNumber")
    public R<MineNumberVo> getMineNumber(String companyCode) {
        return R.ok(groupStatisticService.getMineNumber(companyCode));
    }


}
